cmake_minimum_required(VERSION 3.5)

project(TDomain VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


add_definitions("-DQT_MESSAGELOGCONTEXT")

link_directories(${CMAKE_SOURCE_DIR}/Xlsx/bin)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets  Sql Network Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets  Sql Network Core)

set(PRECOMPILED_HEADER_SOURCE "precomp.h")

set(PROJECT_SOURCES
        precomp.h
        main.cpp
        tdomain.cpp
        tdomain.h
        tdomain.ui
)


if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(TDomain
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}

        Resource.qrc
        database.cpp database.h
        publicstruct.h
        tabulationtemplate.h tabulationtemplate.cpp
        qpagebar.cpp qpagebar.h
        domaindetailinfodlg.h domaindetailinfodlg.cpp domaindetailinfodlg.ui
        clientsocket.h clientsocket.cpp
        customdomaincreatedlg.h customdomaincreatedlg.cpp customdomaincreatedlg.ui
        domainwhoisdlg.h domainwhoisdlg.cpp
        tablecurdtemplate.h tablecurdtemplate.cpp
        dnsuffixwhoismappingdlg.h dnsuffixwhoismappingdlg.cpp
        recorddetailtemplate.h recorddetailtemplate.cpp
        customtreecontrol.h customtreecontrol.cpp
        dndictionarydlg.h dndictionarydlg.cpp
        ctcascader.cpp ctcascader.h
        domainquerydlg.h domainquerydlg.cpp domainquerydlg.ui
        mysqlpool.h
        global.h global.cpp
        multicolumnfilterproxymodel.cpp multicolumnfilterproxymodel.h
        readme.txt
        dncategoryselectdlg.h dncategoryselectdlg.cpp dncategoryselectdlg.ui
        ctclientsocket.h ctclientsocket.cpp
        ctsocketrunnable.h ctsocketrunnable.cpp
        requesttask.cpp requesttask.h
        proxypool.cpp proxypool.h
        proxymgrdlg.h proxymgrdlg.cpp proxymgrdlg.ui
        ctproxyrunnable.h ctproxyrunnable.cpp
        loadandvalidateproxytask.cpp loadandvalidateproxytask.h proxyvalidationtask.cpp proxyvalidationtask.h
        domainquerytask.cpp domainquerytask.h loaddomainquerytask.cpp loaddomainquerytask.h
        ctmaintablemode.cpp ctmaintablemodel.h
        GlobalQueue.h
        sqlitewriter.h sqlitewriter.cpp
        customheaderview.cpp customheaderview.h
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET TDomain APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(TDomain SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(TDomain
            ${PROJECT_SOURCES}
        )
    endif()
endif()

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})



target_link_libraries(TDomain PRIVATE
    Qt${QT_VERSION_MAJOR}::Widgets
#    Qt${QT_VERSION_MAJOR}::Gui
    Qt${QT_VERSION_MAJOR}::Sql
    Qt${QT_VERSION_MAJOR}::Network
    Qt${QT_VERSION_MAJOR}::Core
    QXlsx
)

target_include_directories(TDomain PRIVATE ${CMAKE_SOURCE_DIR}/Xlsx/include/header)
target_precompile_headers(TDomain PRIVATE ${PRECOMPILED_HEADER_SOURCE})


# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.TDomain)
endif()
set_target_properties(TDomain PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS TDomain
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(TDomain)
endif()
